package com.XinYun.Library.modules.person;

import com.XinYun.Library.modules.commons.BasicServlet;
import com.XinYun.Library.modules.person.Service.SqlServiceImpl;
import com.XinYun.Library.utils.HTTPRequestUtils.HTTPRequestUtil;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "changeServlet2", value = "/changeServlet2")
public class changeServlet2 extends HttpServlet {//修改密码
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String json = HTTPRequestUtil.getBody(req);
        //将JSON字符转化为JAVA对象
        System.out.println(req.getContextPath());
        JSONObject jsonObject = JSONObject.parseObject(json);
        String value = jsonObject.getString("uid");
        String value2 = jsonObject.getString("password");
        SqlServiceImpl service =new SqlServiceImpl();
        if(value.equals(""))
        {
            jsonObject.put("code",-1);
            jsonObject.put("message","uid为空");
        }if(value2.equals(""))
        {
            jsonObject.put("code",-1);
            jsonObject.put("message","password为空");
        }else{
            service.change(value,value2);
            jsonObject.put("code",1);
            jsonObject.put("message","修改密码成功");
        }
        PrintWriter writer = resp.getWriter();
        writer.println("修改成功");
        resp.getWriter().write(jsonObject.toString());
    }
}